<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <meta name="description" content="">
    <meta name="author" content="">
    <title>Signin</title>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css"
          integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

    <!-- 可选的 Bootstrap 主题文件（一般不用引入） -->
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"
          integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
</head>

<body>
<div id="alertWrong" style="display: none" class="alert alert-danger" role="alert">name or password wrong !</div>
<div id="alertSuccess" style="display: none" class="alert alert-success" role="alert">welcome home!</div>
<div class="container">

    <form class="form-signin">
        <h2 class="form-signin-heading">Please sign in</h2>
        <label for="inputEmail" class="sr-only">Email address</label>
        <input type="text" id="inputEmail" class="form-control" placeholder="Name" required autofocus>
        <br>
        <label for="inputPassword" class="sr-only">Password</label>
        <input type="password" id="inputPassword" class="form-control" placeholder="Password" required>

        <div class="checkbox">
            <label>
                <input type="checkbox" value="remember-me"> Remember me
            </label>
        </div>
        <button class="btn btn-lg btn-primary btn-block" onclick="bntClick()">Sign in</button>
    </form>

</div>
<!-- /container -->
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"
        integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
        crossorigin="anonymous"></script>

<script type="text/javascript">
    $('form').on('submit', function (e) {
        e.preventDefault()
        // ....
    });
    $("#alertWrong").hide();
    function bntClick() {

        if ($("#inputEmail").val() != "" && $("#inputPassword").val() != "") {

//            $("#alertSuccess").show();
            var url = '/dev/status/'+Date.now();
            console.log(url);
            $.post(url, {name:$("#inputEmail").val(),
                        password:$("#inputPassword").val()
                    },
                    function (data) {
                        if(data.err == 0){
                            $("#alertSuccess").show();
                            setTimeout(function(){
                                $("#alertSuccess").hide("normal","linear",function(){
                                    location.href =data.redirect;
                                });
                            },1000);
                        }else{
                            $("#alertWrong").show();
                            setTimeout(function () {
                                $("#alertWrong").hide("normal", "linear");
                            }, 1000);
                        }
                    }, "json");
        }else{
        }

    }

</script>
</body>
</html>
